package com.study.example.huawei;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Quest01 {
    public static void main(String[] args) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        Integer count = Integer.valueOf(bufferedReader.readLine());
        StringBuffer result = new StringBuffer();
        for (int i = 0; i < count; i++) {
            String str = bufferedReader.readLine();
            if (checkAbsent(str) && checkTwo(str) && checkThree(str) && str.length()<10000){
                result.append("true").append(" ");
            } else {
                result.append("false").append(" ");
            }
        }
        System.out.println(result.substring(0,result.length()-1));
    }

    //判断缺勤是否超过一次
    private static boolean checkAbsent(String str){
        int index = str.indexOf("absent");
        if (index >= 0){
            str = str.substring(index+6);
            if (str.indexOf("absent") >= 0){
                return false;
            }
        }
        return true;
    }

    //判断是否有连续的迟到早退
    private static boolean checkTwo(String str){
        if (str.contains("late late") ||str.contains("leaveearly late") ||str.contains("late leaveearly") || str.contains("leaveearly leaveearly")){
            return false;
        }
        return true;
    }

    //连续7次考勤,缺勤/迟到/早退不超过三次.
    private static boolean checkThree(String str){
        String[] strings = str.split(" ");
        if (strings.length > 7){
            for (int i = 0; i <= strings.length-7; i++) {
                if (!checkContainThree(strings,i,i+7)){
                    return false;
                }
            }
        } else {
            if (!checkContainThree(strings,0,strings.length)){
                return false;
            }
        }
        return true;
    }


    private static boolean checkContainThree(String[] arr, int start ,int end){
        int count = 0;
        for (int i = start; i < end; i++) {
            if (arr[i].equals("absent") || arr[i].equals("late") || arr[i].equals("leaveearly")){
                count++;
            }
        }
        if (count > 3){
            return false;
        }
        return true;
    }

}
